home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / planner / util / indexnode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  2.8 KB  |  109 lines

  1. /*     
  2.  *      FILE
  3.  *         indexnode
  4.  *     
  5.  *      DESCRIPTION
  6.  *         Routines to find all indices on a relation
  7.  * $Header: /private/postgres/src/planner/util/RCS/indexnode.c,v 1.13 1992/03/31 23:14:40 mer Exp $     
  8.  */
  9.  
  10. /*
  11.  *      EXPORTS
  12.  *             find-relation-indices
  13.  */
  14. /* declare (localf (find_secondary_index)); */
  15.  
  16. #include "tmp/postgres.h"
  17.  
  18. #include "parser/parse.h"
  19.  
  20. #include "nodes/plannodes.h"
  21. #include "nodes/relation.h"
  22. #include "nodes/relation.a.h"
  23.  
  24. #include "planner/internal.h"
  25. #include "planner/indexnode.h"
  26. #include "planner/cfi.h"
  27.  
  28. /*    
  29.  *        find-relation-indices
  30.  *    
  31.  *        Returns a list of index nodes containing appropriate information for
  32.  *        each (secondary) index defined on a relation.
  33.  *    
  34.  */
  35.  
  36. /*  .. find-rel-paths
  37.  */
  38.  
  39. LispValue
  40. find_relation_indices (rel)
  41.      Rel rel ;
  42. {
  43.     /*    XXX Cheap temporary hack: 
  44.       if the relation is the result relation, */
  45.     /*      don't use an index to update it! */
  46.  
  47.     if (equal((Node)_query_result_relation_,(Node)get_relids (rel)) && 
  48.     (_query_command_type_ != RETRIEVE )) {
  49.     return (LispNil);
  50.     } else if (get_indexed (rel)) {
  51.     LispValue temp = CAR(get_relids(rel));
  52.     if (IsA(temp,LispInt)) 
  53.       return(find_secondary_index (false,CInteger(temp)));
  54.     } else {
  55.     return (LispNil);
  56.     }
  57.  
  58.     return (LispNil);
  59. }
  60.  
  61. /*    
  62.  *        find-secondary-index
  63.  *    
  64.  *        Creates a list of index path nodes containing information for each
  65.  *        secondary index defined on a relation by searching through the index
  66.  *        catalog.
  67.  *    
  68.  *        'notfirst' is 0 if this is the first call to find-secondary-index
  69.  *        'relid' is the OID of the relation for which indices are being located
  70.  *    
  71.  *        Returns a list of new index nodes.
  72.  *    
  73.  */
  74.  
  75. /*  .. find-relation-indices, find-secondary-index    */
  76.  
  77.  LispValue
  78. find_secondary_index (notfirst,relid)
  79.      bool notfirst;
  80.      ObjectId relid ;
  81. {
  82.     LispValue indexinfo = index_info (notfirst,relid);
  83.     if  ( consp (indexinfo)) {
  84.     Rel indexnode = RMakeRel();
  85.     set_relids (indexnode,lispCons(CAR(indexinfo),LispNil));
  86.     set_pages (indexnode,CInteger(CADR (indexinfo)));
  87.     set_tuples (indexnode,CInteger(nth (2,indexinfo)));
  88.     set_indexkeys (indexnode,nth (3,indexinfo));
  89.     set_ordering (indexnode,nth (4,indexinfo));
  90.     set_classlist (indexnode,nth (5,indexinfo));
  91.     set_indproc(indexnode, CInteger(nth(6,indexinfo)));
  92.     
  93.     set_indexed(indexnode,false);  /* XXX should it be true instead */
  94.     set_size (indexnode,0);
  95.     set_width(indexnode,0);
  96.     set_targetlist(indexnode,LispNil);
  97.     set_pathlist(indexnode,LispNil);
  98.     set_unorderedpath(indexnode,(PathPtr)NULL);
  99.     set_cheapestpath(indexnode,(PathPtr)NULL);
  100.     set_clauseinfo(indexnode,LispNil);
  101.     set_joininfo(indexnode,LispNil);
  102.     set_innerjoin(indexnode,LispNil);
  103.     
  104.     return(lispCons((LispValue)indexnode,
  105.             find_secondary_index (true,relid)));
  106.     } else
  107.       return(LispNil);
  108. }
  109.